package com.powerwyx.shortlink.project.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.powerwyx.shortlink.project.common.convention.result.Result;
import com.powerwyx.shortlink.project.common.convention.result.Results;
import com.powerwyx.shortlink.project.pojo.dto.ShortLinkGroupStatsAccessRecordDTO;
import com.powerwyx.shortlink.project.pojo.dto.ShortLinkGroupStatsDTO;
import com.powerwyx.shortlink.project.pojo.dto.ShortLinkStatsAccessRecordDTO;
import com.powerwyx.shortlink.project.pojo.dto.ShortLinkStatsDTO;
import com.powerwyx.shortlink.project.pojo.vo.ShortLinkStatsAccessRecordVO;
import com.powerwyx.shortlink.project.pojo.vo.ShortLinkStatsVO;
import com.powerwyx.shortlink.project.service.ShortLinkStatsService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author 王艺锡
 * @version 1.0
 */
@Slf4j
@RestController
@RequestMapping("/api/shortlink/v1/stats")
public class ShortLinkStatsController {

    @Autowired
    private ShortLinkStatsService shortLinkStatsService;

    /**
     * 访问单个短链接指定时间内监控数据
     */
    @GetMapping("/getSingleStats")
    public Result<ShortLinkStatsVO> shortLinkStats(ShortLinkStatsDTO shortLinkStatsDTO) {
        return Results.success(shortLinkStatsService.oneShortLinkStats(shortLinkStatsDTO));
    }

    /**
     * 访问分组短链接指定时间内监控数据
     */
    @GetMapping("/group")
    public Result<ShortLinkStatsVO> groupShortLinkStats(ShortLinkGroupStatsDTO shortLinkGroupStatsDTO) {
        return Results.success(shortLinkStatsService.groupShortLinkStats(shortLinkGroupStatsDTO));
    }


    /**
     * 访问单个短链接指定时间内访问记录监控数据
     */
    @GetMapping("/accessrecord")
    public Result<IPage<ShortLinkStatsAccessRecordVO>> shortLinkStatsAccessRecord(ShortLinkStatsAccessRecordDTO shortLinkStatsAccessRecordDTO) {
        return Results.success(shortLinkStatsService.shortLinkStatsAccessRecord(shortLinkStatsAccessRecordDTO));
    }


    /**
     * 访问分组短链接指定时间内访问记录监控数据
     */
    @GetMapping("/accessrecord/group")
    public Result<IPage<ShortLinkStatsAccessRecordVO>> groupShortLinkStatsAccessRecord(ShortLinkGroupStatsAccessRecordDTO shortLinkGroupStatsAccessRecordDTO) {
        return Results.success(shortLinkStatsService.groupShortLinkStatsAccessRecord(shortLinkGroupStatsAccessRecordDTO));
    }


}
